#!/usr/bin/python3
import sys

def part1():
    print('part 1')
    max_cal = 0
    max_elf = 0
    current_cal = 0
    current_elf = 1
    for line in sys.stdin:
        if line.strip() == '':
            if current_cal > max_cal:
                max_cal = current_cal
                max_elf = current_elf
            current_cal = 0
            current_elf += 1
            continue
        current_cal += int(line.rstrip('\n'))

    print(f'elf {max_elf} has {max_cal} calories')
    print(f'{max_cal}')

def part2(n):
    print('part 2')
    top = [0 for i in range(n)]
    cal = 0
    for line in sys.stdin:
        if line.strip() == '':
            if cal > min(top):
                new_top = []
                j = 0
                for i in range(n):
                    if top[j] > cal:
                        new_top.append(top[j])
                        j += 1
                    else:
                        new_top.append(cal)
                        cal = 0
                top = new_top
            cal = 0
            continue
        cal += int(line.strip())
    print(f'top {top} -> {sum(top)}')

if sys.argv[1] in '1':
    part1()
else:
    part2(3)